#ifndef __BUSINESSSERVICE_H__ 
#define __BUSINESSSERVICE_H__ 

#include "Message.hpp"
#include "TcpConnection.hpp"
#include "MySQLClient.hpp"

#include <stdio.h>
extern "C"
{
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
#include <libavcodec/avcodec.h>
}

#include <string>
#include <iostream>
using std::cerr;
using std::cout;
using std::endl;
using std::string;



//登录1
class UserLoginSection1
{
public:
    UserLoginSection1(wd::TcpConnectionPtr conn, const wd::Packet & p)
        : _conn(conn)
          , _packet(p)
    {

    }

    ~UserLoginSection1(){
        cout <<"~UserLoginSection1" << endl;
    }


    //业务逻辑的处理
    void process();


private:
    wd::TcpConnectionPtr _conn;
    wd::Packet _packet;

};


//登录2
class UserLoginSection2
{
public:
    UserLoginSection2(wd::TcpConnectionPtr conn, const wd::Packet & p)
        : _conn(conn)
          , _packet(p)
    {}

    //业务逻辑的处理
    void process();


private:
    wd::TcpConnectionPtr _conn;
    wd::Packet _packet;
};


//注册1
class UserRegisterSection1
{
public:
    UserRegisterSection1(wd::TcpConnectionPtr conn, const wd::Packet & p)
        : _conn(conn)
          , _packet(p)
    {}

    //业务逻辑的处理
    void process();


private:
    wd::TcpConnectionPtr _conn;
    wd::Packet _packet;

};


//注册2
class UserRegisterSection2
{
public:
    UserRegisterSection2(wd::TcpConnectionPtr conn, const wd::Packet & p)
        : _conn(conn)
          , _packet(p)
    {}

    //业务逻辑的处理
    void process();


private:
    wd::TcpConnectionPtr _conn;
    wd::Packet _packet;

};

//获取列表

class UserGetCameraList
{
public:
    UserGetCameraList(wd::TcpConnectionPtr conn, const wd::Packet & p)
        :_conn(conn)
         ,_packet(p)
    {}

    void process();

private:
    wd::TcpConnectionPtr _conn;
    wd::Packet _packet;

};


//发送AVPacket到Qt客户端
class UserGetRTSP
{
public:
    UserGetRTSP(wd::TcpConnectionPtr conn, const wd::Packet & p)
        :_conn(conn)
         ,_packet(p) 
         ,pFormatCtx(nullptr)
         ,avdic(nullptr)
        
    {

    }

    ~UserGetRTSP(){
        cout << "~UserGetRTSP" << endl;
    }



    void process();

    void init(){

        //初始化FFmepg网络模块
        avformat_network_init();

        //封装容器上下文结构体
        pFormatCtx = avformat_alloc_context();

        //设置网络传输的传输层协议
        char option_key[] = "rtsp_transport";
        char option_value[] = "udp";
        av_dict_set(&avdic,option_key,option_value,0);

        char option_key2[] = "max_delay";
        char option_value2[] = "100";
        av_dict_set(&avdic,option_key2,option_value2,0);
    }




private:
    wd::TcpConnectionPtr _conn;
    wd::Packet _packet;

    AVFormatContext * pFormatCtx;
    AVDictionary    * avdic;

};


class UserGetRecordings
{
public:
    UserGetRecordings(wd::TcpConnectionPtr conn, const wd::Packet & p)
        :_conn(conn)
         ,_packet(p)
    {}

    void process();

    void sendRecordingFile(const string& path);
    void sendAVPacketAsTLV(const AVPacket& pkt);

private:
    wd::TcpConnectionPtr _conn;
    wd::Packet _packet;

};






#endif
